import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDkeMME88iJU6/WumRe+J/FbrfV' +
  'ThP1S7EweJI7Aj6Ht/i6ExDs+iNh2OZrO952avZcSRkgzu2WeDzGqJIQkj3ZE8gz' +
  'OKQsFbpz8XjbnUOIver74+zljNUkJlmqxzPwYJRARhvrW+o4ASID+SCy04XHnFr6' +
  'CoBOiv3FggzV6qC32wIDAQAB';

const privateKey = 'MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAOR4wwTzyIlTr9a6' +
  'ZF74n8Vut9VOE/VLsTB4kjsCPoe3+LoTEOz6I2HY5ms73nZq9lxJGSDO7ZZ4PMao' +
  'khCSPdkTyDM4pCwVunPxeNudQ4i96vvj7OWM1SQmWarHM/BglEBGG+tb6jgBIgP5' +
  'ILLThcecWvoKgE6K/cWCDNXqoLfbAgMBAAECgYEAwxsVf38nu45J1Rdra2bqGdIJ' +
  'DxEUHh+7euccCWRLPd8veseZZqXd3Us6ykxgF8QUCo8p9EiBwEOBsyx1P82DHeYj' +
  'wN3z3auNZTGxuDgQEXGHpqbWM/AwVHbvU4WxphYc+VdpYMcNJlZJdjDxWn0rndbS' +
  'fjJxX9anR3XN4ZHBTJECQQD+Jxp6qgD5bYoGNwurfHucgl9CYvOc3bvHL8alvQPb' +
  'Eb+Iv3JGq9zpDJQGRguo/yt51RVncFKskdm+GLKn1vi/AkEA5iHfzcE/q3DWDYOB' +
  '5nyx/Jl9sFihr4rGxw3QBJGJoy6wCQPqXaT58x2thlZ2BxDrjNp+MqrBYgaHUfCl' +
  'WlwL5QJAVC8HqlHdeME70ssw5mCZYUId45N7Nh6MMHI2zndJa6r5UoZ3h8ktp1Qv' +
  'Q9S30AaVlAlsyZJ/EAJPqZPsuYOPaQJAN3pdEKYQqkzGXXWhgCX5ZnK+OR/0wnPL' +
  'Hbt3tVI8gwlDSLkX68FUvEYgSe1YALYUgt09ZQuDGRWH07oWsqTT/QJBAKz12Mvt' +
  'nrzwBkInNGa0eIS7/YCJ/jhIv97wzglj4JJ8Onovc13a1a8QKdqqUkdVxP7poCid' +
  'WRkcXUB7m/ZLpPA=';

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPublicKey(publicKey) // 设置公钥
  return encryptor.encrypt(txt) // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt()
  encryptor.setPrivateKey(privateKey) // 设置私钥
  return encryptor.decrypt(txt) // 对数据进行解密
}
